package com.zyk.leetcode;

import java.util.Arrays;

/**
 * @author zhangsan
 * @date 2021/4/30 21:12
 */
public class C338 {

    // 暴力解
    public static int[] countBits(int num) {
        int[] ans = new int[num + 1];
        for (int i = 0; i <= num; i++) {
            ans[i] = countBit(i);
        }
        return ans;
    }

    private static int countBit(int num) {
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if( (num >> i & 1) != 0) count++;
        }
        return count;
    }


    // for test
    public static void main(String[] args) {
        int num = 200;
        System.out.println(Arrays.toString(countBits(num)));
    }

}
